<style scoped>
  .rj-topbar {
    height: 50px; line-height: 50px; background: #f7f7f7; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative
  }
  .list {
    background: #eee;
  }
  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui_navbar_item {
    font-size: 14px;
  }
  .weui_navbar_item.weui_bar_item_on {
    color: #3cc51f;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .list {
    overflow: auto;
  }
  .rj-cell {
    display: inline-block;
    font-size: 0;
    padding: 5px 6px;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell.minpad{
    padding-right: 10px !important;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
  }
  .rj-cell span {
    padding-left: 5px;
    font-size: 14px;
    color: #333;
  }
  .rj-cell.note{
    width: 100%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cells {
    margin-top: 0;
  }
  .rj-wrap {
    background: #eee;
    overflow:auto;overflow-x: hidden
  }
  .rj-cont {
    background: #fff;
  }
  .weui-panel {
    background: #eee;
  }
  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }
  .weui-panel {
    margin-top: 0;
    text-align: left;
  }
  .hd .weui-grid.js_grid {
    font-weight: 600;
  }
  .weui-grid.js_grid {
    width: 20%;
    padding: 10px 1px;
  }
  .weui-grid.fir {
    width: 30%;
  }
  .weui-grid.sec {
    width: 20%;
  }
  .weui-grid.thr {
    width: 20%;
  }
  .weui-grid.fou {
    width: 15%;
  }
  .weui-grid.fiv {
    width: 15%;
  }
  .weui-grid__label {
    text-overflow: initial;
  }
</style>
<template>
  <div>
    <div class="rj-wrap">
      货运单详情
      <a href="javascript:;" @click="toPrevUrl($route.query.fromurl)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px" />
      </a>
    </div>
    <div class="weui-panel weui-panel_access">
      <div class="weui-panel__bd">
        <div class="weui-form-preview billitem rj-cont-tit">
          <div class="rj-cell max">
            <label>货运单编号：</label>
            <span>{{baseInfo.code}}</span>
          </div>
          <div class="rj-cell max">
            <label>采收合同：</label>
            <span>{{contract.name}}</span>
          </div>
          <div class="rj-cell max">
            <label>种植户：</label>
            <span>{{baseInfo.plantor}}  {{baseInfo.plantorphone}}</span>
          </div>
          <div class="rj-cell max">
            <label>地块：</label>
            <span>{{baseInfo.arealand}}</span>
          </div>
          <div class="rj-cell max">
            <label>承运人：</label>
            <span>{{baseInfo.carcode}}</span>
            <span>{{baseInfo.drivername}}</span>
            <span>{{baseInfo.driverphone}}</span>
          </div>
          <div class="rj-cell max">
            <label>货品：</label>
            <span>{{baseInfo.variety + ' ' + baseInfo.specification}}</span>
          </div>
          <div>
            <div class="rj-cell max" v-if="contract.regionName">
              <label>区域：</label>
              <span style="color: red;">{{contract.regionName}}</span>
            </div>
            <div class="rj-cell max" v-if="contract.seriesName">
              <label>系列：</label>
              <span style="color: red;">{{contract.seriesName}}</span>
            </div>
          </div>
          <div class="rj-cell max">
            <label>库房：</label>
            <span>{{baseInfo.storeroom}}</span>
          </div>
          <div class="rj-cell max">
            <label>付款方式：</label>
            <span>{{getPaytype(baseInfo.setlwgtype)}}</span>
          </div>
          <div class="rj-cell max">
            <label>状态：</label>
            <span>{{baseInfo.statusname}}</span>
          </div>
          <div class="rj-cell max">
            <label>负责人：</label>
            <span>{{baseInfo.operator}}</span>
          </div>
          <div class="rj-cell max">
            <label>装车时间：</label>
            <span>{{baseInfo.createtime}}</span>
          </div>
          <div class="rj-cell max">
            <label><img src="../../../../static/image/icon-location.png" width="15px" height="15px" /></label>
            <span>{{baseInfo.address}}</span>
          </div>
          <div class="rj-cell max">
            <label><img src="../../../../static/image/icon-distance.png" width="15px" height="15px" /></label>
            <span>  {{baseInfo.distance}} Km</span>
          </div>
          <div class="rj-cell max">
            <label>卸货时间：</label>
            <span>{{baseInfo.unloadtime}}</span>
          </div>
          <div class="rj-cell max">
            <label>备注：</label>
            <span>{{baseInfo.remark}}</span>
          </div>
        </div>
      </div>
      <div class="weui-panel__hd" v-if="qaform != ''">
        质检单
        <i class="weui-icon-info-circle" @click="toQainfo()" style="float: right;font-size: 22px;"></i>
      </div>
      <div class="weui-panel__bd" style="background: #fff;">
        <div class="weui-form-preview billitem rj-cont-tit">
          <div class="rj-cell max">
            <label>质检标准：</label>
            <span>{{baseInfo.qaname}}</span>
          </div>
          <div class="rj-cell max">
            <label>扣杂方式：</label>
            <span>{{baseInfo.deducttypeName}}</span>
          </div>
          <div class="rj-cell max">
            <label>扣杂标准：</label>
            <span>{{baseInfo.isdiscountName}}</span>
          </div>
          <template v-if="baseInfo.deducttype == 1">
            <div class="rj-cell max">
              <label>合同扣杂率：</label>
              <span>{{contract.discountrate + '%'}}</span>
            </div>
            <div class="rj-cell max">
              <label>质检扣杂率：</label>
              <span>{{qaform.deductrate + '%'}}</span>
            </div>
            <div v-if="baseInfo.deductRateByHand" class="rj-cell max">
              <label>手工扣杂率：</label>
              <span>{{baseInfo.deductRateByHand + '%'}}</span>
            </div>
            <div class="rj-cell max">
              <label>最终扣杂率：</label>
              <span>{{baseInfo.ratend + '%'}}</span>
            </div>
            <div class="rj-cell max" v-if="baseInfo.qamaintype == 2">
              <label>淀粉含量：</label>
              <span>{{dianfen}}</span>
            </div>
          </template>
          <template v-if="baseInfo.deducttype == 2">
            <div class="rj-cell max" v-if="qaform.soilchkrate">
              <label>土杂率：</label>
              <span>{{qaform.soilchkrate + '%'}}</span>
            </div>
            <div class="rj-cell max" v-if="baseInfo.isdiscount != 6 && qaform.unqualifiedchkrate">
              <label>不合格率：</label>
              <span>{{qaform.unqualifiedchkrate + '%'}}</span>
            </div>
            <div class="rj-cell max" v-if="baseInfo.isdiscount == 6 && baseInfo.acceptStatus">
              <label>质检结果：</label>
              <span>{{baseInfo.acceptStatus == 1 ? '合格' : '不合格'}}</span>
              <span style="color: #0BB20C;font-size: 12px;" @click="viewQaform">详情 >></span>
            </div>
          </template>
          <div class="rj-cell max">
            <label>质检人员：</label>
            <span>{{qaform.operatorname}}</span>
          </div>
          <div class="rj-cell max">
            <label>质检时间：</label>
            <span>{{qaform.createdate}}</span>
          </div>
        </div>

      </div>
      <div class="weui-panel__hd">
        结算信息
      </div>
      <div class="weui-panel__bd" style="background: #fff;">
        <div class="weui-form-preview billitem rj-cont-tit">
            <template v-if="baseInfo.deducttype == 1">
              <div class="rj-cell max" v-if="baseInfo.qamaintype == 2">
                <label>淀粉单价：</label>
                <span>{{baseInfo.unitPrice + ' 元/淀粉含量*吨'}}</span>
              </div>
              <div class="rj-cell max">
                <label>合同单价：</label>
                <span>{{baseInfo.price + ' 元/吨'}}</span>
              </div>
            </template>
            <template v-if="baseInfo.deducttype == 2">
              <div class="rj-cell max" style="width: 100%;display: flex;">
                <label style="display: inline-flex;">合同单价：</label>
                <div style="width: 70%;">
                  <p>
                    <label>合格薯：</label>
                    <span>{{passPrice ? passPrice : baseInfo.price + ' 元/吨'}}</span>
                  </p>
                  <p>
                    <label>淀粉薯：</label>
                    <span>{{unpassPrice + ' 元/吨'}}</span>
                  </p>
                </div>
              </div>
            </template>
          <div class="rj-cell max" v-if="baseInfo.weight">
            <label>拉货重量：</label>
            <span>{{baseInfo.weight}} 吨</span>
          </div>
          <template v-if="baseInfo.netWeight > 0">
            <div class="rj-cell max">
              <label>毛重：</label>
              <span>{{baseInfo.hweight}} 吨</span>
            </div>
            <div class="rj-cell max">
              <label>入库重量：</label>
              <span>{{baseInfo.netWeight}} 吨</span>
            </div>
            <div class="rj-cell max">
              <label>每件毛重：</label>
              <span>{{baseInfo.wghtperpkg}} Kg</span>
            </div>
            <div class="rj-cell max">
              <label>包装物重量：</label>
              <span>{{baseInfo.pkgwgh}} Kg</span>
            </div>
          </template>
          <div class="rj-cell max">
            <label>结算重量：</label>
            <span>{{baseInfo.setlwgtype == 1 ? baseInfo.weight : baseInfo.hweight}} 吨</span>
          </div>
          <div class="rj-cell max" v-if="baseInfo.settlement">
            <label>结算金额：</label>
            <span>{{baseInfo.settlement}} 元</span>
            <template v-if="baseInfo.deducttype == 2">
              <p v-if="baseInfo.isdiscount != 6" style="font-size: 12px;text-align: left;margin-right: 10px">= 合格薯单价 * 合格薯重量 * (1 - 土杂率 - 不合格率) + 不合格薯单价 * 不合格薯重量 * 不合格率</p>
              <p v-if="baseInfo.isdiscount == 6" style="font-size: 12px;text-align: left;margin-right: 10px">= (合同单价 + 奖励金额 - 扣罚金额) * 结算重量</p>
            </template>
            <template v-if="baseInfo.deducttype == 1">
              <p style="font-size: 12px;text-align: left;margin-right: 10px">= 合同单价 * (1 - 最终扣杂率) * 结算重量</p>
            </template>
          </div>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
  import SalesOperationLogs2 from '../../common/SalesOperationLogs2'

  export default {
    data () {
      return {
        id: '',
        qaform: '',
        baseInfo: '',
        contract: '',
        constants: [],
        price: '',
        awardamount: '',
        deductamount: '',
        whinform: '',
        dianfen: ''
      }
    },
    components: {
      SalesOperationLogs2
    },
    mounted () {
      console.log(1111111111)
      console.log('$route.query.fromurl:', decodeURIComponent(this.$route.query.fromurl))
      this.id = this.$route.query.id;
      this.getBaseinfo(this.id);
    },
    activated() {
      // console.log(1111111111)
      // console.log('$route.query.fromurl:', decodeURIComponent(this.$route.query.fromurl))
      // this.id = this.$route.query.id;
      // this.getBaseinfo(this.id);
    },
    computed: {
      passPrice: function () {
        if (this.constants.length == 0) return;
        return (this.constants.filter(item => {
          return item.type == 1;
        })[0] || '') .price;
      },
      unpassPrice: function () {
        if (this.constants.length == 0) return;
        return (this.constants.filter(item => {
          return item.type == 2;
        })[0] || '').price;
      }
    },
    methods: {
      getPaytype: function(type) {
        let name = '';
        if (type == 1) {
          name = '地头付';
        } else if (type == 2) {
          name = '验收付';
        }
        return name;
      },
      toQainfo: function() {
        const path = encodeURIComponent(location.href);
        location.href = `/harvest/Qarecord!detail.action?s=${this.baseInfo.guid}&door=fodetail&fromurl=${path}`;
      },
      viewQaform: function() {
        this.$router.push({name: 'ViewQaform', query: {id: this.baseInfo.guid, fromurl: encodeURIComponent(location.href)}});
      },
      getBaseinfo: function (id) {
        this.axios({
          method: 'post',
          url: '/harvest/Freightorder!getAcceptInfo.action',
          params: {guid: id}
        }).then(response => {
          if (response.data.msg == 'success') {
            this.baseInfo = response.data.order || {};
            this.qaform = response.data.qaform || '';
            this.contract = response.data.contract || {};
            this.whinform = response.data.whinform || {};
            this.constants = response.data.constants || [];
            this.price = response.data.price || '';
            this.awardamount = response.data.awardamount || '';
            this.deductamount = response.data.deductamount || '';
            if (this.baseInfo.qamaintype == 2) {
              //获取质检单淀粉含量
              this.getDianfen(this.baseInfo.guid);
            }
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastError('系统错误！');
          }
        });
      },
      getDianfen: function(id) {
        this.axios({
          method: 'post',
          url: '/harvest/Qaresult!getDianfengContent.action',
          params: {foguid: id}
        }).then(response => {
          if (response.data.status == 'true') {
            this.dianfen = response.data.result;
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastText('获取质检单淀粉含量错误');
          }
        });
      },
      openLogs: function() {
        if (this.sellform.flag == 3) {
          this.$router.push({name: 'SalesOperationLogs2', query: {orderid: this.id, srguid: this.sellform.storermguid, departid: this.sellform.depguid, sellformpid: this.sellform.parentguid, sellformpcode: this.sellform.parentcode}});
        } else {
          this.$router.push({name: 'SalesOperationLogs2', query: {orderid: this.id, srguid: this.sellform.storermguid, departid: this.sellform.depguid}});
        }
      },
    }
  }
</script>
